#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN WEB SERVER

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For use in commercial software, please obtain a commercial license from THN Solutions LLC.    

  + For use in free software, this library is licensed under GPL version 3. A summary of 
	GPLv3 is listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt 
	included with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 15-Nov-12 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;

using Thn;
using Thn.IO;
using Thn.Net;
using Thn.Net.Http;
#endregion

namespace Thn.Web
{
    /// <summary>
    /// Information about a file to be sent. Used internally by <see cref="FileHandlerBase"/>.
    /// </summary>
#if DEBUG || TESTING
    public
#else
    public
#endif
 class FileSendInfo : PoolableObject
    {
        #region Fields
        /// <summary>
        /// Size of the send buffer.
        /// </summary>
        public const int BufferSize = 100000;
        /// <summary>
        /// The current request-response handling context.
        /// </summary>
        public IHttpRequestHandlingContext Context;
        /// <summary>
        /// Offset from beginning of file to be sent.
        /// </summary>
        public long Offset;
        /// <summary>
        /// Number of bytes to be sent this time.
        /// </summary>
        public long Length;
        /// <summary>
        /// Total number of bytes the file actually occupies.
        /// </summary>
        public long TotalLength;
        /// <summary>
        /// URI of the file requested.
        /// </summary>
        public string Uri;
        /// <summary>
        /// Absolute path to the local file.
        /// </summary>
        public string AbsoluteLocalFilePath;
        /// <summary>
        /// Extension of the file.
        /// </summary>
        public string FileExtension;
        /// <summary>
        /// Buffer used for sending file.
        /// </summary>
        public byte[] Buffer;
        /// <summary>
        /// Whether the channel should be closed after sending is completed.
        /// </summary>
        public bool KeepAlive;
        /// <summary>
        /// The current file resource to read from.
        /// </summary>
        public IFileResource Resource;
        /// <summary>
        /// Whether all data should be sent at once or split into multiple chunks.
        /// <para>Default is true.</para>
        /// </summary>
        public bool SendAllAtOnce = true;
        /// <summary>
        /// Does the response contain only a portion of the content or the whole?
        /// <para>Default is false.</para>
        /// </summary>
        public bool IsPartialContent = false;
        /// <summary>
        /// Whether the file should be sent automatically after processing logic is done.
        /// </summary>
        public bool AutoSend = true;
        #endregion

        #region Properties
        #endregion

        #region To String
        public override string ToString()
        {
            return string.Format("Offset: {0:#,#0} Length: {1:#,#0} TotalLength: {2:#,#0} Uri: {3}", Offset, Length, TotalLength, Uri);
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor.
        /// </summary>
        public FileSendInfo()
        {
            Buffer = new byte[BufferSize];
        }
        #endregion
    }
}
